package com.viroyal.monitorlib.network.socket;

/**
 * Created by cxy_nj on 2016/9/20.
 */

public class DeviceConnectStatus {
    public static final int DEV_CONNECTING = 1;//正在连接
    public static final int DEV_CONNECTED = 2;//链接成功
    public static final int DEV_DISCONNECTING = 3;//正在断开
    public static final int DEV_DISCONNECTED = 4; //空闲状态
    public static final int DEV_WAIT_RECONNECT = 5; //已经启动了重连的timer
    //socket层面，只用以上几个状态来表示连接状态
    public static final int DEV_REG_SUCCESS = 6;//注册成功
    public static final int DEV_REG_FAILED = 7;//注册失败
    public static final int DEV_LOGIN_SUCCESS = 8;//登陆成功
    public static final int DEV_LOGIN_FAILED = 9;//登陆失败
    public static final int DEV_NETWORK_LOST = 10;//网络异常

    private int deviceStatus = DEV_DISCONNECTED;//设备状态

    public DeviceConnectStatus() {
    }

    public DeviceConnectStatus(int deviceStatus) {
        this.deviceStatus = deviceStatus;
    }

    public int getDeviceStatus() {
        return deviceStatus;
    }

    public void setDeviceStatus(int deviceStatus) {
        this.deviceStatus = deviceStatus;
    }

    public boolean isIdle() {
        return (DEV_DISCONNECTED == deviceStatus) ? true : false;
    }

    public boolean canDisconnect() {
        return (deviceStatus == DEV_CONNECTED);
    }

    @Override
    public String toString() {
        String msg;
        switch (deviceStatus) {
            case DEV_CONNECTING:
                msg = "DEV_CONNECTING";
                break;
            case DEV_CONNECTED:
                msg = "DEV_CONNECTED";
                break;
            case DEV_DISCONNECTING :
                msg = "DEV_DISCONNECTING ";
                break;
            case DEV_DISCONNECTED :
                msg = "DEV_DISCONNECTED";
                break;
            case DEV_WAIT_RECONNECT:
                msg = "DEV_WAIT_RECONNECT";
                break;
            default:
                msg = "code:" + deviceStatus;
        }
        return msg;
    }
}
